package 子集;

import java.util.ArrayList;
import java.util.List;

class Solution {
    List<List<Integer>> ret;
    List<Integer> path;
    public List<List<Integer>> subsets(int[] nums) {
        ret = new ArrayList<>();
        path = new ArrayList<>();
        dfs1(nums,0);
//        dfs2(nums, 0);
        return ret;
    }

    //方法一:
    public void dfs1(int[] nums, int pos){
        if(pos == nums.length){
            ret.add(new ArrayList(path));
            return;
        }
        path.add(nums[pos]);
        dfs1(nums, pos + 1);
        path.remove(path.size() - 1);
        dfs1(nums, pos + 1);
    }

    //方法二:
    public void dfs(int[] nums, int pos){
        ret.add(new ArrayList<>(path));
        for(int i = pos; i < nums.length; i++){
            path.add(nums[i]);
            dfs(nums, i + 1);
            path.remove(path.size() - 1);
        }
    }
}